package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;
    /**
     * 分页查询护理项目
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProject> page = nursingProjectMapper.selectByPage(name, status);
        return PageResponse.of(page, NursingProjectVo.class);
    }

    /**
     * 新增护理项目
     *
     * @param nursingProjectDto
     */
    @Override
    public void addNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProject.setCreateTime(LocalDateTime.now());
        nursingProject.setCreateBy(1L);
        nursingProjectMapper.addNursingProject(nursingProject);
    }

    /**
     * 删除护理项目根据id
     *
     * @param id
     */
    @Override
    public void deleteNursingProjectById(Long id) {
        nursingProjectMapper.deleteNursingProjectById(id);
    }

    /**
     * 查询护理项目根据id
     *
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo getNursingProjectById(Long id) {
        return nursingProjectMapper.getNursingProjectById(id);
    }

    /**
     * 修改护理项目
     *
     * @param nursingProjectDTO
     */
    @Override
    public void updateNursingProject(NursingProjectDto nursingProjectDTO) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDTO, NursingProject.class);
        nursingProjectMapper.updateNursingProject(nursingProject);
    }

    /**
     * 修改护理项目状态
     *
     * @param id
     * @param status
     */
    @Override
    public void enableOrDisable(Long id, Integer status) {
        nursingProjectMapper.enableOrDisable(id, status);
    }

    /**
     * 查询所有护理项目
     *
     * @return
     */
    @Override
    public List<NursingProjectVo> getAll() {
        return nursingProjectMapper.getAll();
    }
}
